package com.grom.service;

import java.util.List;

import com.grom.dao.DepartmentDao;
import com.grom.dao.RelationSecToDepDao;
import com.grom.po.Department;
import com.grom.po.RelationSecToDep;

public interface DepartmentService {
	DepartmentService instance = new DepartmentService() {

		public List<Department> getAllDepartment() {
			return DepartmentDao.instance.getAllDepartments();
		}

		public Department getDepartmentByID(String id) {
			return DepartmentDao.instance.getDepartmentByID(id);
		}

		public void add(Department department) {
			DepartmentDao.instance.add(department);
		}

		public void update(Department department) {
			DepartmentDao.instance.update(department);
		}

		public void delete(Department department) {
			DepartmentDao.instance.delete(department);
		}

		public List<Department> selectByCondition(String sql) {
			return DepartmentDao.instance.selectByCondition(sql);
		}

		public Department getDepartmentByUserId(String userId) {
			String sql = "select * from department where id = (select departmentid from relationdeptouser where userid = '"
					+ userId + "')";
			List<Department> result = DepartmentDao.instance
					.selectByCondition(sql);
			if (result == null || result.size() == 0) {
				return new Department();
			}
			return result.get(0);
		}

		public void addRelationToSec(RelationSecToDep relation) {
			RelationSecToDepDao.instance.add(relation);
		}

		public void removeRelationToSec(RelationSecToDep relation) {
			RelationSecToDepDao.instance.remove(relation);
		}

	};

	List<Department> getAllDepartment();

	Department getDepartmentByID(String id);

	Department getDepartmentByUserId(String userId);

	void add(Department department);

	void update(Department department);

	void delete(Department department);

	void addRelationToSec(RelationSecToDep relation);

	void removeRelationToSec(RelationSecToDep relation);

	List<Department> selectByCondition(String sql);
}
